Skip to content

fix(core): only Studio's own preview pages get the editing port, and undo sets only safe attributes - #8057

Merged
miguel-heygen merged 3 commits into
mainfrom
fix/studio-restore-attrs-allowlist
Nov 17, 2026
Merged

miguel-heygen merged 3 commits into
mainfrom
fix/studio-restore-attrs-allowlist

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

What

Two changes to the preview's editing channel, the message port a preview page hands its parent so Studio can read and edit the composition in place.

  1. restore-attributes only changes attributes on an allowlist. An undo applied in place may set class, style and the timing, layout, audio and label data- attributes Studio's editor writes (data-start, data-duration, data-track-index, data-volume, data-x and so on), and may drop those, loading, or any other data- attribute (the live page carries the preview's own markers and the loading="lazy" the preview server adds to timed images, which the saved file does not). Any other change, such as an event handler, a URL attribute (src, href, srcdoc, xlink:href, data-composition-src) or sandbox, makes the frame answer applied: false and change nothing; Studio then reloads the preview, as it does for every other restore it cannot apply in place. Attributes whose value is already what the file says are no longer set again, so an image's unchanged src is left alone.
  2. The port goes only to a page Studio's own preview server marked. The runtime used to hand the port to any parent unless the page carried the "served to another site" mark, so a page served by anything else with no mark at all (a project page from another local server, say) gave the port to whatever site framed it. It now hands it over only when the page carries Studio's preview mark (<meta name="hyperframes-studio-preview">, which the preview route already stamps on every page it serves, Desktop's included) and not the another-site mark. A page with no mark never gets the port.

Why

Before this, a site that could frame a preview page and get the port could send restore-attributes with an onerror or src attribute and run script in the page's origin, which can read the project's files. The allowlist stops the attribute half; the positive mark stops a page that never asked for an editing parent from offering one.

Related work

Follows #8009, which added restore-attributes.

How

  • packages/core/src/runtime/editing/restoreAttributes.ts: the plan now works out, per element, the attributes it would drop and the ones whose value it would change, and refuses the whole restore before touching anything when one is outside the allowlist.
  • packages/core/src/studioPreviewMark.ts: markedForStudio(doc) is the Studio mark present and the another-site mark absent; installEditingAgent asks it instead of only checking the another-site mark.
  • The tests that install the agent use a small installMarkedEditingAgent helper (editingAgent.test-helpers.ts) that adds the Studio mark, since that is now what a page needs to hand over the port.

Test plan

On a Linux box against this main (this branch's code):

  • packages/core, each file on its own, 3 runs in a row, all pass every run: restoreAttributes.test.ts (5), editingAgent.test.ts (149), editingPort.test.ts (11), editingGeometry.test.ts (4), editingHandles.test.ts (12), color-grading.test.ts (17). bun run typecheck exits 0.

  • packages/studio, same way: gsapUndoRestore.sealed.test.ts (3), gsapUndoRestore.test.ts (44), CaptionOverlay.sealed.test.ts (5), LayersPanel.opaque.test.ts (3), previewDrafts.test.ts (13), previewGestureStartRead.test.ts (6), previewLayers.test.ts (7), previewOverlayRects.test.ts (9), previewPointerTargets.test.ts (16), previewSelection.test.ts (28), useColorGradingController.sealed.test.ts (4). bun run typecheck exits 0.

  • oxfmt check, oxlint (0 warnings, 0 errors) and fallow audit --base origin/main (no issues) on the changed files.

  • fails without the fix: with only the test changes applied to main, "changes no handler, URL or sandbox-style attribute, and leaves an unchanged one alone" in packages/core/src/runtime/editing/restoreAttributes.test.ts and "never hands off in a document Studio's preview server did not mark" in packages/core/src/runtime/editingAgent.test.ts fail; every other test in the files below passes on main and on this branch.

  • Unit tests added/updated

  • Manual testing performed

  • Documentation updated (if applicable)

  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

What I did NOT exercise

  • No browser run of Studio or Desktop with this branch; the Studio mark is already on every page the preview route serves (injectStudioPreviewAugmentations), and Desktop serves its previews through the same route.
  • An undo that changes an attribute outside the allowlist now reloads the preview where fix(studio): an undo on a sealed preview shows in place, not after a reload #8009 applied it in place. Undoing a media swap that changes src, for one, reloads again.
  • A project file that itself contains <meta name="hyperframes-studio-preview"> and is served by some other server would still offer the port. That needs the project's author, who already runs script in that page.
  • No macOS or Windows run.

…undo sets only safe attributes

restore-attributes now changes only class, style and the editor's timing, layout, audio and label data- attributes, and drops only data- ones; any other change answers applied: false and Studio reloads the preview. The editing agent hands its port over only when the page carries Studio's preview mark and not the another-site mark, so a page no Studio marked never offers it.

@vanceingalls vanceingalls left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at 8a0635a.

  • What restore can set: a fixed set of 19 names, matched exactly (class, style and 17 named data-*). Case and whitespace variants and on* handlers fall outside it and are refused.
  • What restore can remove: only that set plus data-*.
  • When it refuses: the whole restore is refused before anything changes, and gsapUndoRestore reloads the preview once, so there's no reload loop.
  • Port gate: the port goes only to a page carrying Studio's preview mark, the meta that preview.ts stamps on pages it serves. A Studio page framed by another site gets the another-site meta plus the sandbox allow-scripts CSP from createStudioApi, so markedForStudio is false and it gets no port.
  • Test: the fails without the fix: line is present.

Should-fix:

  1. Lazy images: lazyPreviewImages adds loading="lazy" to images with a start time, and dropping it is now refused, so undo on any lazy image always reloads. Allow removing loading, or note the regression.
  2. Handoff target: the port is still handed over with postMessage(..., "*") to event.source === parent, so the meta is the only gate. Pin the handoff to the iframe Studio created (or its origin) when convenient.

The preview server adds loading="lazy" to timed images and the saved file does not have it, so the restore now may drop loading; dropping it loads nothing new.
@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Thanks. Both should-fixes:

  1. Lazy images: fixed in 4932320. The preview server adds loading="lazy" to timed images and the saved file does not have it, so the restore may now drop loading (dropping it loads nothing new). The image case in restoreAttributes.test.ts now carries loading="lazy" and the preview's lazy marker; it fails on 8a0635a (expected { applied: false } to deeply equal { applied: true }) and passes with this commit, 3 runs.
  2. Handoff target: left as is in this PR. The recipient is already the parent window object (event.source === parent), and the frame cannot pin an origin it is never told: a sealed preview runs on an opaque origin and Studio's origin is not passed in. A page framed by another site carries the another-site mark and never reaches the handoff. Pinning the handoff to the iframe Studio created needs a value Studio hands the frame first, which is a protocol change of its own; happy to take it as a follow-up.

@vanceingalls vanceingalls left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approved at 4932320. This covers my lazy-image should-fix: safeToDrop now also allows removing loading, so undo on a lazily loaded image applies in place. loading is still not settable, so nothing new can be added.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 110 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (8)

Unstable (2)

  • seqplainkeys-none-px-r0-root-z100: tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo false, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true
  • seqab-none-center-r0-root-z100: tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true

@vanceingalls vanceingalls left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approved at 70e8eaf. This is a style-only change: one doc-comment line wrapped to fit the line limit.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit 55291c0 Nov 17, 2026
98 checks passed
@miguel-heygen
miguel-heygen deleted the fix/studio-restore-attrs-allowlist branch November 17, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants